<?php

/*

  Action	$5

  Trash 2 cards from your hand.
  If you do, gain a silver card; put it into your hand.

 */

class TradingPost extends Card implements iAction, iKingdom, iIntrigue {

    public function __construct() {
        parent::__construct("Trading Post", 5);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "Trash 2 cards from your hand.",
            "If you do, gain a silver card; put it into your hand.");
    }
    
    public function play(Game $game, $isRealCard) {

        $playHand = $game->getPlayHand();
        if (sizeof($playHand) > 2) {
             
            $output = MySocket::GetUserReply($game, Input_ChooseMany, $playHand, 2, 2, null, "Choose 2 cards to trash");
             ScreenDisplay::addScreenMessage($game, true, "trash " . nicePrint($output), "trashes " .ScreenDisplay::$LMSG);
            foreach ($output as $card_name) {
                $game->moveCardFromPileToPile($card_name, PlayHand, Trash);
            }
            $silver = $game->moveCardFromPileToPile("Silver", BoardCards, PlayHand);
             ScreenDisplay::addScreenMessage($game, false, " and gain ".  nicePrint($silver), " and gains ". ScreenDisplay::$LMSG);
        } else if (sizeof($playHand) == 2) {
             ScreenDisplay::addScreenMessage($game, true, "trash " . nicePrint($playHand), "trashes " . ScreenDisplay::$LMSG);
            foreach ($playHand as $card) {
                $silver = $game->moveCardFromPileToPile($card, PlayHand, Trash);
                 ScreenDisplay::addScreenMessage($game, false, " and gain ".  nicePrint($silver), " and gains ". ScreenDisplay::$LMSG);
            }
            $game->moveCardFromPileToPile("Silver", BoardCards, PlayHand);
        } else {
             ScreenDisplay::addScreenMessage($game, true, "trash " . nicePrint($playHand), "trashes " . ScreenDisplay::$LMSG);
            foreach ($playHand as $card) {
                $game->moveCardFromPileToPile($card, PlayHand, Trash);
            }
        }
        $game->cardActionFinished();
        return true;
    }

}

?>